﻿<?php
	$ym = $_GET['ym'];
	if($ym < 1)$ym = 1;
	$url = 'http://top.baidu.com/buzz?b='.$ym;
    
    
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec($ch);
    curl_close($ch); 
	//$html = file_get_contents($url);

	$pos = strpos($html,'utf-8');
	preg_match("/<title>(.*)<\/title>/i",$html, $title);
	if(!$pos && count($title) > 1)
	{
		$title[1] = iconv("gbk","utf-8",$title[1]);
	}
	//echo $title[1];

	$arr = array();
	$arrzs = array();
	for($i = 0;$i < 10;$i ++)
	{
		$html = strstr($html, '<a class="list-title"');
		$html = strstr($html, '">');
		$a = strpos($html,'/a') - 1;
		$wenben = mb_substr($html , 0 , $a);
		
		$wenben = str_replace('">','',$wenben);

		$wenben = iconv("gb2312","utf-8//IGNORE",$wenben);
		array_push($arr, $wenben);


		$html = strstr($html, '<td class="last">');
		$html = strstr($html, 'icon-');
		$html = strstr($html, '>');
		$a = strpos($html,'/span>') - 2;
		$wenben = mb_substr($html , 1 , $a);
		
		$wenben = str_replace('ise">','',$wenben);

		$wenben = iconv("gb2312","utf-8//IGNORE",$wenben);
		array_push($arrzs, $wenben);

	}
	$html = file_get_contents('bangdan.htm');
	for($i = 0;$i < count($arr);$i ++)
	{
		$jkm = ($ym - 1) * 10 + $i;
		$url = 'tz.php?word='.$arr[$i].'&jkm='.$jkm;
		$html = str_replace('_anters_'.$i.'_zs',$arrzs[$i],$html);
		$html = str_replace('_anters_'.$i.'_lj',$url,$html);
		$html = str_replace('_anters_'.$i,$arr[$i],$html);
	}
	$html = str_replace('a id = "ym'.$ym.'" href="redian.php?ym='.$ym.'"','a id = "ym'.$ym.' href="javascript:void(0);" class = "dangqian"',$html);
	if(count($title) > 1)$html = str_replace('今日实时热点',$title[1],$html);
	
	echo $html;
?>